/**
 * @summary 文章模块
 */
import * as articleApi from '@/api/article';

export default {
  namespaced: true,
  state: {
    // 文章列表
    articleList: [],
    articleDetails: [],
    articleDetailsId: -1,
    articleComments: [],
  },
  mutations: {
    SET_ARTICLE_LIST(state, newValue) {
      state.articleList = newValue;
    },
    SET_ARTICLE_DETAILS(state, newValue) {
      state.articleDetails = newValue;
    },
    SET_ARTICLE_DETAILS_Id(state, newId) {
      state.articleDetails = newId;
    },
    SET_ARTICLE_COMMENTS(state, newValue) {
      state.articleComments = newValue;
    },
  },
  actions: {
    async updateArticleList({ commit }, id) {
      const res = await articleApi.getArticleList(id);
      commit('SET_ARTICLE_LIST', res);
    },
    async updateArticleDetails({ commit }, id) {
      const res = await articleApi.getArticleDetails(id);
      commit('SET_ARTICLE_DETAILS', res);
    },
    async updateArticleComments({ commit }, id) {
      const res = await articleApi.getArticleComments(id);
      commit('SET_ARTICLE_COMMENTS', res);
    },
  },
}
